<?php


namespace app\api\controller\v1;


use ApiOper;
use app\common\controller\UserBaseController;
use hiredis;

class XiaoController extends UserBaseController
{

    function init_system_oper_info()
    {
        $this->user_info = [
            'id' => '0',
            'name' => 'SYSTEM',
            'phone' => '9527',
            'user_type' => OPER_TYPE_SYSTEM,
            'channel' => 'SYSTEM'
        ];
        ApiOper::instance()->_user_info = $this->user_info;
        //hilog::set_xiao_an_log_path();
    }

    function callbackAction()
    {
        $this->init_system_oper_info();

        $this->paramlist = [
            'success' => 'bool',
            'data' => 'array',
        ];

        $this->check_params();
        $imei = $this->argv['data']['imei'];

        if (empty($imei)) {
            $this->throw_myexception(ERROR_QUERY_INFO, "empty imei");
        }
        //$bike_info = BikeModel::instance()->get_info_by_imei($imei);
        if (empty($bike_info)) {
            // exit();
            // throw_myexception(ERROR_QUERY_INFO, "query bike info error");
        };


        hiredis::db()->lPush('ECU_EVENT_QUEUE', json_encode($this->argv['data']));
        $r = rand(0, 200);
        if ($r == 1) {
            $l = hiredis::db()->lLen('ECU_EVENT_QUEUE');
            if ($l > 10000) {
                hiredis::db()->lTrim('ECU_EVENT_QUEUE', 0, 5000);
            }
        }

        return $this->ret_resp();
    }

}
